<template>
  <div class="app-container">
    <!-- 对话框(添加 / 修改) -->
    <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="45%" v-dialogDrag append-to-body>
      <el-form ref="formRef" :model="formData" :rules="formRules" v-loading="formLoading" label-width="100px">
                    <el-form-item label="关联的团id" prop="teamOrdeId">
                      <el-input v-model="formData.teamOrdeId" placeholder="请输入关联的团id" />
                    </el-form-item>
                    <el-form-item label="关联的团号" prop="teamOrdeNumbers">
                      <el-input v-model="formData.teamOrdeNumbers" placeholder="请输入关联的团号" />
                    </el-form-item>
                    <el-form-item label="1：收客团款 2：地接团款" prop="type">
                      <el-select v-model="formData.type" placeholder="请选择1：收客团款 2：地接团款">
                            <el-option label="请选择字典生成" value="" />
                      </el-select>
                    </el-form-item>
                    <el-form-item label="项目" prop="name">
                      <el-input v-model="formData.name" placeholder="请输入项目" />
                    </el-form-item>
                    <el-form-item label="单价" prop="price">
                      <el-input v-model="formData.price" placeholder="请输入单价" />
                    </el-form-item>
                    <el-form-item label="数量" prop="number">
                      <el-input v-model="formData.number" placeholder="请输入数量" />
                    </el-form-item>
                    <el-form-item label="备注" prop="remark">
                      <el-input v-model="formData.remark" placeholder="请输入备注" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column1">
                      <el-input v-model="formData.column1" placeholder="请输入自定义" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column2">
                      <el-input v-model="formData.column2" placeholder="请输入自定义" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column3">
                      <el-input v-model="formData.column3" placeholder="请输入自定义" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column4">
                      <el-input v-model="formData.column4" placeholder="请输入自定义" />
                    </el-form-item>
                    <el-form-item label="自定义" prop="column5">
                      <el-input v-model="formData.column5" placeholder="请输入自定义" />
                    </el-form-item>
      </el-form>
              <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" :disabled="formLoading">确 定</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import * as OrdePaymentApi from '@/api/team/ordepayment';
      export default {
    name: "OrdePaymentForm",
    components: {
                    },
    data() {
      return {
        // 弹出层标题
        dialogTitle: "",
        // 是否显示弹出层
        dialogVisible: false,
        // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
        formLoading: false,
        // 表单参数
        formData: {
                            id: undefined,
                            teamOrdeId: undefined,
                            teamOrdeNumbers: undefined,
                            type: undefined,
                            name: undefined,
                            price: undefined,
                            number: undefined,
                            remark: undefined,
                            column1: undefined,
                            column2: undefined,
                            column3: undefined,
                            column4: undefined,
                            column5: undefined,
        },
        // 表单校验
        formRules: {
                        teamOrdeId: [{ required: true, message: '关联的团id不能为空', trigger: 'blur' }],
                        teamOrdeNumbers: [{ required: true, message: '关联的团号不能为空', trigger: 'blur' }],
                        type: [{ required: true, message: '1：收客团款 2：地接团款不能为空', trigger: 'change' }],
                        name: [{ required: true, message: '项目不能为空', trigger: 'blur' }],
                        price: [{ required: true, message: '单价不能为空', trigger: 'blur' }],
        },
                        };
    },
    methods: {
      /** 打开弹窗 */
     async open(id) {
        this.dialogVisible = true;
        this.reset();
        // 修改时，设置数据
        if (id) {
          this.formLoading = true;
          try {
            const res = await OrdePaymentApi.getOrdePayment(id);
            this.formData = res.data;
            this.title = "修改团款项目";
          } finally {
            this.formLoading = false;
          }
        }
        this.title = "新增团款项目";
              },
      /** 提交按钮 */
      async submitForm() {
        // 校验主表
        await this.$refs["formRef"].validate();
                  this.formLoading = true;
        try {
          const data = this.formData;
                  // 修改的提交
          if (data.id) {
            await OrdePaymentApi.updateOrdePayment(data);
            this.$modal.msgSuccess("修改成功");
            this.dialogVisible = false;
            this.$emit('success');
            return;
          }
          // 添加的提交
          await OrdePaymentApi.createOrdePayment(data);
          this.$modal.msgSuccess("新增成功");
          this.dialogVisible = false;
          this.$emit('success');
        } finally {
          this.formLoading = false;
        }
      },
                      /** 表单重置 */
      reset() {
        this.formData = {
                            id: undefined,
                            teamOrdeId: undefined,
                            teamOrdeNumbers: undefined,
                            type: undefined,
                            name: undefined,
                            price: undefined,
                            number: undefined,
                            remark: undefined,
                            column1: undefined,
                            column2: undefined,
                            column3: undefined,
                            column4: undefined,
                            column5: undefined,
        };
        this.resetForm("formRef");
      }
    }
  };
</script>